package com.zz.parkingsystem.exception;

import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wangyuxiang
 * 全局异常处理，降低耦合
 */

@RestControllerAdvice
public class ValidExceptionHandler {
    @ExceptionHandler(BindException.class)
    public Result validExceptionHandler(BindException exception){
        return ResultGenerator.genFailResult(exception.getBindingResult().getFieldError().getDefaultMessage());
    }
}
